<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('includes/functions/module_functions.php');
class ot_total {

	function ot_total() {
		$this->module_key = 'MODULE_ORDER_TOTAL_TOTAL';
		$this->code = 'ot_total';
		$this->enabled = ((MODULE_ORDER_TOTAL_TOTAL_STATUS == 'true') ? true : false);
		$this->sort_order = MODULE_ORDER_TOTAL_TOTAL_SORT_ORDER;
	}

	function process($params, &$checkout_component)
	{
		$price = 0.0;

		$cart_prices = &$checkout_component->cart_prices;
		reset($cart_prices);
		foreach ($cart_prices as $key => $value)
    		{
			$price += $value['value'];
		}
		$cart_prices[$this->code] = array('value' => $price, 'title' => 'Total:', 'class' => $this->code);
	}

	function check() {
		if (!isset($this->_check)) {
			$this->_check = check_module($this->module_key);
		}
		return $this->_check;
	}

	function install() {
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, configuration_values, date_added) values ('Display Coupon', 'MODULE_ORDER_TOTAL_TOTAL_STATUS', 'true', 'Do you want to display the total discount?', '6', '1','true, false', now())");
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_TOTAL_SORT_ORDER', '100', 'Sort order of display.', '6', '2', now())");
	}

	function remove() {
		remove_module($this->module_key);
	}
}
?>
